package cn.com.pajx.pajx_smart_platform.tools;

import android.util.Log;

import cn.com.pajx.pajx_smart_platform.BuildConfig;

/**
 * create by ruancw on 2023/04/03
 * description Log日志输出工具
 */
public class LogUtil {
    private static String TAG = "ruancw";//类名
    private static String className;//类名

    /**
     * 判断是否可以调试
     *
     * @return true/false
     */
    private static boolean isDebuggable() {
        return !BuildConfig.DEBUG;
    }

    private static String createLog(String log) {
        return className + "-->" + log;
    }

    /**
     * 获取文件名、方法名、所在行数
     *
     * @param sElements sElements
     */
    private static void getMethodNames(StackTraceElement[] sElements) {
        className = sElements[1].getFileName();
    }

    public static void e(String message) {
        if (isDebuggable())
            return;
        getMethodNames(new Throwable().getStackTrace());
        Log.e(TAG, createLog(message));
    }

    public static void i(String message) {
        if (isDebuggable())
            return;
        getMethodNames(new Throwable().getStackTrace());
        Log.i(TAG, createLog(message));
    }

    public static void d(String message) {
        if (isDebuggable())
            return;
        getMethodNames(new Throwable().getStackTrace());
        Log.d(TAG, createLog(message));
    }

    public static void v(String message) {
        if (isDebuggable())
            return;
        getMethodNames(new Throwable().getStackTrace());
        Log.v(TAG, createLog(message));
    }

    public static void w(String message) {
        if (isDebuggable())
            return;
        getMethodNames(new Throwable().getStackTrace());
        Log.w(TAG, createLog(message));
    }
}
